package com.mouliu.base.syn007;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerTest {
    public static final AtomicInteger atomicInteger = new AtomicInteger(0);
   private static void atomicInteger(){
       ExecutorService executorService = Executors.newFixedThreadPool(10000);
       for (int i=0;i<10000;i++){
           executorService.execute(()->{
               for (int j=0;j<4;j++){
                   System.out.println(atomicInteger.getAndIncrement());
               }
           });
       }
       executorService.shutdown();
   }
    public static void main(String[] args) throws InterruptedException {
        atomicInteger();

        Thread.sleep(3000);
        System.out.println("最终结果是" + atomicInteger.get());
    }
}
